package com.mindskip.xzs.controller.admin;

import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.component.QywxComponent;
import com.mindskip.xzs.service.QywxService;
import com.mindskip.xzs.viewmodel.admin.qywx.QywxDepartment;
import com.mindskip.xzs.viewmodel.admin.qywx.QywxDepartmentTree;
import com.mindskip.xzs.viewmodel.admin.qywx.QywxDepartmentTreeV1;
import com.mindskip.xzs.viewmodel.admin.qywx.QywxUser;
import com.mindskip.xzs.viewmodel.wx.student.qywx.MiniProgramNotice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author guoguangkai
 * @since 2022/9/13
 */
@RestController("QywxController")
@RequestMapping(value = "/api/admin/qywx")
public class QywxController {
    @Resource
    private QywxService qywxService;
    @Resource
    private QywxComponent qywxComponent;

    /**
     * 获取部门列表
     * @param id 部门id。获取指定部门及其下的子部门（以及子部门的子部门等等，递归）。 如果不填，默认获取全量组织架构
     */
    @GetMapping("/department/list")
    public RestResponse<List<QywxDepartment>> listDepartment(@RequestParam(required = false, value = "id") Long id) {
        return RestResponse.ok(qywxService.getDepartmentList(id));
    }

    /**
     * 获取部门成员
     * @param departmentId 获取的部门id
     */
    @GetMapping("/user/list")
    public RestResponse<List<QywxUser>> listUser(@RequestParam("departmentId") Long departmentId) {
        return RestResponse.ok(qywxService.getUserList(departmentId));
    }

    /**
     * 获取部门和人员树
     *
     * @param useCache 非必须，默认true，当为false时会拉取最新数据并更新缓存
     * @return
     */
    @GetMapping("/departAndUser/tree")
    public RestResponse<QywxDepartmentTree> queryDepartAndUserTree(@RequestParam(required = false, value = "useCache", defaultValue = "true") Boolean useCache) {
        return RestResponse.ok(qywxService.getDepartAndUserTree(useCache));
    }

    /**
     * 获取部门和人员树V1
     */
    @GetMapping("/departAndUser/tree/v1")
    public RestResponse<List<QywxDepartmentTreeV1>> queryDepartAndUserTreeV1() {
        return RestResponse.ok(qywxService.getDepartAndUserTreeV1());
    }

    /**
     * 推送企业微信消息
     */
    @PostMapping("/msg/send")
    private RestResponse<Boolean> sendMsg(
            //@RequestBody MiniProgramNotice msg
    ) {
        return RestResponse.ok(qywxComponent.sendMsg(new MiniProgramNotice()));
    }
}
